const tokens = {
	admin: {
		token: 'admin-token'
	},
	editor: {
		token: 'editor-token'
	}
}

const users = {
	'admin-token': {
		roles: ['admin'],
		introduction: 'I am a super administrator',
		avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
		name: 'Super Admin',
		menuList: [
			{
				path: '/dashboard',
				name: 'Dashboard',
				redirect: '/dashboard/index.vue'
			},
			{
				path: '/Example',
				name: 'Example',
				meta: {
					title: 'Example',
					icon: 'el-icon-menu'
				},
				redirect: '/Example/icons',
				children: [
					{
						path: 'directives',
						name: 'Directives',
						meta: { title: 'Directives', noCache: true }
					},
					{
						path: 'icons',
						name: 'Icons',
						meta: { title: 'Icons', noCache: true }
					},
					{
						path: 'buttons',
						name: 'Button',
						meta: { title: 'Button', noCache: true }
					},
					{
						path: 'Tree',
						name: 'Tree',
						meta: { title: 'Tree', noCache: true }
					},
					{
						path: 'table',
						name: 'Table',
						meta: { title: 'table', noCache: true }
					},
					{
						path: 'inlineEditTable',
						name: 'InlineEditTable',
						meta: { title: 'inlineEditTable', noCache: true }
					}
				]
			}
		]
	},
	'editor-token': {
		roles: ['editor'],
		introduction: 'I am an editor',
		avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
		name: 'Normal Editor',
		menuList: [
			{
				path: '/dashboard',
				name: 'Dashboard',
				redirect: '/dashboard/index.vue'
			},
			{
				path: '/Example',
				name: 'Example',
				meta: {
					title: 'Example',
					icon: 'el-icon-menu'
				},
				redirect: '/Example/icons',
				children: [
					{
						path: 'directives',
						name: 'Directives',
						meta: { title: 'Directives', noCache: true }
					},
					{
						path: 'icons',
						name: 'Icons',
						meta: { title: 'Icons', noCache: true }
					},
					{
						path: 'buttons',
						name: 'Button',
						meta: { title: 'Button', noCache: true }
					},
				]
			},
			{
				path: '/sys',
				name: 'Sys',
				meta: {
					title: 'Sys',
					icon: 'el-icon-menu',
				},
				redirect: '/sys/dept',
				children: [
					{
						path: 'dept',
						component: () => import('@/views/button/index'),
						name: 'Dept',
						meta: { title: 'dept', noCache: true },
					},
				],
			},
		]
	}
}

module.exports = [
	// user login
	{
		url: '/vue-element-admin/user/login',
		type: 'post',
		response: config => {
			const { username } = config.body
			const token = tokens[username]
			const info = users['admin-token']
			// mock error
			if (!token) {
				return {
					code: 60204,
					message: 'Account and password are incorrect.'
				}
			}

			return {
				code: 20000,
				data: {
					token,
					...info
				}
			}
		}
	},

	// get user info
	{
		url: '/vue-element-admin/user/info.*',
		type: 'get',
		response: config => {
			const { token } = config.query
			const info = users[token]

			// mock error
			if (!info) {
				return {
					code: 50008,
					message: 'Login failed, unable to get user details.'
				}
			}

			return {
				code: 20000,
				data: info
			}
		}
	},

	// user logout
	{
		url: '/vue-element-admin/user/logout',
		type: 'post',
		response: _ => {
			return {
				code: 20000,
				data: 'success'
			}
		}
	}
]
